/**
 * KopsoxFramework
 * Copyright (C) 2010 Free Software Foundation, Inc. <http://fsf.org/>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kopsox.util.xml.parser;

import java.lang.reflect.Constructor;

import org.kopsox.util.xml.parser.exception.KopsoxXMLParserException;



/**
 * This factory creates an XML-Parser
 * 
 * @author Konrad Renner - 23.07.2010
 */
public final class XMLParserFactory {

	private XMLParserFactory() {
		//Factory
	}
	
	/**
	 * Creates an XML-Parser
	 * 
	 * @param <T> 
	 * @param implementingClass
	 * @param pathToXml
	 * @return KopsoxXMLParser
	 * @throws KopsoxXMLParserException 
	 */
	public static <T extends KopsoxXMLParser> T getXMLParser(final Class<T> implementingClass, final String pathToXml) throws KopsoxXMLParserException {
		
		try {
			Object[] conArr = {pathToXml};
			
			Constructor<T> constructor = implementingClass.getConstructor(String.class);
			
			return constructor.newInstance(conArr);
			
		}catch(Throwable th) {
			throw new KopsoxXMLParserException(th);
		}
	}
}
